package com.landian.commons.jpa.hql;

import java.util.List;
import java.util.stream.Collectors;

/**
 * QueryPart构建器
 *
 * @author caojl
 * @create 2017/12/19
 **/
public class QueryPartBuilder {

    public static QueryPart path(String path, ParameterUnit parameterUnit, OperationType operationType) {
        PathPredicate pathPredicate = PathPredicate.newInstance(path, parameterUnit, operationType);
        return QueryPart.newInstance(parameterUnit,pathPredicate);
    }

    public static QueryPart keyWord(List<String> pathList, OperationType operationType, String name, Object value){
        ParameterUnit parameterUnit = ParameterUnit.newInstance(name, value);
        List<PredicateHql> predicateList = pathList.stream().map(path -> PathPredicate.newInstance(path, parameterUnit, operationType)).collect(Collectors.toList());
        PredicateHql predicateHqlOr = PredicateHqlOr.newInstance(predicateList, parameterUnit);
        return QueryPart.newInstance(parameterUnit, predicateHqlOr);
    }
}
